var o, e = require, t = module, n = exports, i = this && this.__extends || (o = function(t, e) {
    return (o = Object.setPrototypeOf || {
        __proto__: []
    } instanceof Array && function(t, e) {
        t.__proto__ = e;
    } || function(t, e) {
        for (var n in e) e.hasOwnProperty(n) && (t[n] = e[n]);
    })(t, e);
}, function(t, e) {
    function n() {
        this.constructor = t;
    }
    o(t, e), t.prototype = null === e ? Object.create(e) : (n.prototype = e.prototype, 
    new n());
}), a = this && this.__decorate || function(t, e, n, i) {
    var o, r = arguments.length, a = r < 3 ? e : null === i ? i = Object.getOwnPropertyDescriptor(e, n) : i;
    if ("object" == typeof Reflect && "function" == typeof Reflect.decorate) a = Reflect.decorate(t, e, n, i); else for (var s = t.length - 1; 0 <= s; s--) (o = t[s]) && (a = (r < 3 ? o(a) : 3 < r ? o(e, n, a) : o(e, n)) || a);
    return 3 < r && a && Object.defineProperty(e, n, a), a;
};

Object.defineProperty(n, "__esModule", {
    value: !0
});

var r = e("PopItemView"), s = e("TryItemView"), c = e("Global"), l = e("GameManager"), d = e("ActionView"), u = e("AudioManager"), p = e("MyButton"), h = e("GameConfig"), f = e("GameData"), g = e("AdManager"), m = cc._decorator, y = m.ccclass, v = m.property, w = function(e) {
    function t() {
        var t = null !== e && e.apply(this, arguments) || this;
        return t.layout = null, t.backLabel = null, t.imageList = [], t.titleSprite = null, 
        t.item = null, t.items = [], t.type = 0, t;
    }
    return i(t, e), t.prototype.onLoad = function() {
        (GA.isOPPO() || GA.isPlatform(GA.Platform.Vivo)) && (this.backLabel.fontSize = 40);
    }, t.prototype.onClick = function(t) {
        h.GC.isFreeTry && f.GD.updateNumber("tryFreeCount", -1) ? this.callback(t) : t.target.getComponent(p.default).onClick(t);
    }, t.prototype.onClickBack = function() {
        u.default.getInstance().playAudio("按钮2"), f.GD.updateNumber("tryFailCount", 1), 
        e.prototype.onClickBack.call(this);
    }, t.prototype.start = function() {
        this.myButton && (this.myButton.tag = this.text, this.myButton.viewname = this.viewname, 
        this.myButton.btnname = this.btnname, this.myButton.init()), cc.systemEvent.on(this.text, this.callback, this), 
        this.init();
    }, t.prototype.init = function() {
        var e = this;
        if (f.GD.topRank >= c.G.gunModelList.length && f.GD.skins.length >= c.G.personModelList.length) this.closePnl(); else {
            f.GD.skins.length >= c.G.personModelList.length || 2001 == f.GD.gunIdx ? this.type = 1 : f.GD.topRank >= c.G.gunModelList.length ? this.type = 0 : this.type = Math.random() < .5 ? 0 : 1;
            var t = this.getSkinIdxs();
            if (0 != t.length) {
                this.type < this.imageList.length && (this.titleSprite.spriteFrame = this.imageList[this.type]);
                for (var n = this.item.node.width * t.length, i = 0; i < t.length; i++) {
                    var o, r = cc.instantiate(this.item.node), a = r.getComponent(s.default);
                    a && ((o = r.getComponent(d.default)) && (o.delay = .15 * i), r.x = -n / 2 + r.width * (i + .5), 
                    r.parent = this.layout, r.active = !0, this.items.push(a), a.init(this.type, t[i]));
                }
                this.items.forEach(function(t) {
                    return t.myButton.init(e.text);
                });
            } else this.closePnl();
        }
    }, t.prototype.callback = function(t) {
        f.GD.tryFailCount = 0;
        t = t.target;
        if (t && t.parent) {
            var e = t.parent.getComponent(s.default);
            switch (this.type) {
              case 0:
                c.G.tryPersonIdx = e.idx, c.G.tryPersonMap.set(c.G.tryPersonIdx, {
                    id: c.G.tryPersonIdx,
                    time: -1
                });
                break;

              case 1:
                c.G.tryGunIdx = e.idx;
            }
        }
        this.closePnl();
    }, t.prototype.getSkinIdxs = function() {
        switch (this.type) {
          case 0:
            return this.getPersonIdxs();

          case 1:
            return this.getGunIdxs();

          default:
            return [];
        }
    }, t.prototype.getPersonIdxs = function() {
        return f.GD.skins.length >= c.G.personModelList.length ? [] : f.GD.skins.length > c.G.personModelList.length - 3 ? c.G.personModelList.filter(function(t) {
            return !f.GD.hasSkin(t.id);
        }).map(function(t) {
            return t.id;
        }) : c.G.personModelList.filter(function(t) {
            return !f.GD.hasSkin(t.id);
        }).map(function(t) {
            return t.id;
        }).sort(function() {
            return Math.random() - .5;
        }).slice(0, 3);
    }, t.prototype.getGunIdxs = function() {
        return f.GD.topRank >= c.G.gunModelList.length ? [] : f.GD.topRank > c.G.gunModelList.length - 3 ? c.G.gunModelList.filter(function(t) {
            return t.id > f.GD.topRank && t.id < f.GD.topRank + 5;
        }).map(function(t) {
            return t.id;
        }) : c.G.gunModelList.filter(function(t) {
            return t.id > f.GD.topRank && t.id < f.GD.topRank + 5;
        }).map(function(t) {
            return t.id;
        }).sort(function() {
            return Math.random() - .5;
        }).slice(0, 3);
    }, t.prototype.closePnl = function() {
        g.default.getInstance().hideAllBanner(), l.default.getInstance().matchType == l.MatchType.三对三 ? l.default.getInstance().battleGame() : l.default.getInstance().matchGame();
    }, a([ v(cc.Node) ], t.prototype, "layout", void 0), a([ v(cc.Label) ], t.prototype, "backLabel", void 0), 
    a([ v([ cc.SpriteFrame ]) ], t.prototype, "imageList", void 0), a([ v(cc.Sprite) ], t.prototype, "titleSprite", void 0), 
    a([ v(s.default) ], t.prototype, "item", void 0), a([ y ], t);
}(r.default);

n.default = w;